﻿@inherits Vowei.Web.G18nWebViewPage<System.Collections.Generic.IEnumerable<Vowei.Data.Models.Statistics.DateTimeWorkStatistics>>
@using Vowei.Web.Helpers

<div class="statistics">
    <script type="text/javascript">        
        function max(arr, f) {
            var maxVal = null;
            for ( var i = 0; i < arr.length; ++i ) {
               if ( maxVal == null )
                    maxVal = f(arr[i]);
               else 
                    maxVal = Math.max(maxVal, f(arr[i]));
            }

            return maxVal;
        };

        function min(arr, f) {
            var minVal = null;
            for ( var i = 0; i < arr.length; ++i ) {
               if ( minVal == null )
                    minVal = f(arr[i]);
               else 
                    minVal = Math.min(minVal, f(arr[i]));
            }

            return minVal;
        };

        var data = @Html.Raw((string)ViewData[Vowei.Web.Helpers.ViewHelpers.JsonObjectKey]);          

        var w = 500,
            h = 400,
            x = pv.Scale.linear(data, function(d) d.Item).range(0, w),
            y = pv.Scale.linear(0, 100).range(0, h);

        var vis = new pv.Panel()
            .width(w)
            .height(h)
            .bottom(20)
            .left(20)
            .right(10)
            .top(5);

        vis.add(pv.Rule)
            .data(x.ticks())
            .visible(function(d) d > 0)
            .left(x)
            .strokeStyle("#eee")
          .add(pv.Rule)
            .bottom(-5)
            .height(5)
            .strokeStyle("#000")
          .anchor("bottom").add(pv.Label)
            .text(x.tickFormat);

        vis.add(pv.Rule)
            .data(y.ticks(5))
            .bottom(y)
            .strokeStyle(function(d) d ? "#eee" : "#000")
          .anchor("left").add(pv.Label)
            .text(y.tickFormat);

        vis.add(pv.Line)
            .data(data)
            .interpolate("step-after")
            .left(function(d) x(d.Item))
            .bottom(function(d) y(d.ActiceTasksCount))
            .lineWidth(3);

        vis.render();
    </script>
</div>